<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="../css/denglv.css">
</head>

<body>
    <div class="logon">
        <div>
            <strong>登录账户</strong>
        </div>
        <div class="input">
            <p>
                <span class="before">7-10个字符以内的字母、数字下划线的组合</span> 账号: <input type="text" id="txt" name="uname">
                <i class=""></i>
                <span class="after">用户名格式不正确</span>
            </p>
            <p>
                <span class="before">6位纯数字密码</span> 密 码: <input type="password" id="pwd" name="uname">
                <i class=""></i>
                <span class="after">用户名格式不正确</span>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="登录" id="save" disabled>
            </p>
        </div>
    </div>
    <script>
        var txt = document.getElementById("txt")
        var pwd = document.getElementById("pwd")
        txt.onfocus = pwd.onfocus = function() {
            this.parentNode.firstElementChild.style.display = "block";
        }

        function fn(user_input, reg) {
            user_input.parentNode.firstElementChild.style.display = "none";
            var user = user_input.value;

            if (reg.test(user)) {
                user_input.nextElementSibling.className = "ok"
                user_input.parentNode.lastElementChild.style.display = "none";
            } else {
                user_input.nextElementSibling.className = "err"
                user_input.parentNode.lastElementChild.style.display = "inline-block";
            }
            var num = document.querySelectorAll(".input p .ok")
            if (num.length == 2) {
                save.disabled = false
            } else {
                save.disabled = true
            }
        }
        txt.onblur = function() {
            fn(this, /^\w{7,10}$/ig);
        }
        pwd.onblur = function() {
                fn(pwd, /^\d{6}$/ig)
            }
            // sessionStorage.setItem("denglv", "true")
        save.onclick = function() {
            sessionStorage["text"] = txt.value;
            sessionStorage["pwd"] = pwd.value;
            location.href = "neichadian.html";
            sessionStorage["denglv"] = "true"
        }
    </script>
</body>

</html>